// Kony


#include "AbilitySystem/Abilitys/BaseGameplayAbility.h"

#include "AbilitySystem/BaseAttributeSet.h"

//定义可重写能力描述函数 用于各技能编写能力描述
FString UBaseGameplayAbility::GetDescription(int32 Level, const FText& Title, const FText& Description)
{
	return FString::Printf(TEXT("<Default>%s, </><Level>%d</>"),L"默认能力名称 - LoremIpsum LoremIpsum LoremIpsum LoremIpsum LoremIpsum LoremIpsum LoremIpsum LoremIpsum LoremIpsum LoremIpsum LoremIpsum LoremIpsum LoremIpsum LoremIpsum LoremIpsum LoremIpsum LoremIpsum LoremIpsum LoremIpsum LoremIpsum",Level);
}
//定义可重写下一级能力描述函数 用于各技能下一级编写能力描述
FString UBaseGameplayAbility::GetNextLevelDescription(int32 Level, const FText& Title, const FText& Description)
{
	return FString::Printf(TEXT("<Default>下一级: </><Level>%d</> \n<Default>造成更多伤害.</>"),Level);
}
//获取锁定描述(用于没有符合解锁条件，被锁定的法术)
FString UBaseGameplayAbility::GetLockedDescription(int32 Level)
{
	return FString::Printf(TEXT("<Default>法术等级锁定: %d</>"), Level);
}
//通用描述生成模板函数
FString UBaseGameplayAbility::FormatAbilityDescription(int32 Level, const FText& Title, const FText& Description, const TArray<FStringFormatArg>& Args) const
{
	FString FormattedDescription;
	if (!Description.IsEmpty())
	{
		FormattedDescription = FString::Format(*Description.ToString(), Args);
		FormattedDescription = FormattedDescription.Replace(TEXT("\\n"), TEXT("\n"));
	}
	
	const float ManaCost = FMath::Abs(GetManaCost(Level));
	const float Cooldown = GetCooldown(Level);
	
	return FString::Printf(TEXT(
		"<Title>%s</>\n"
		"<Small>等级: </><Level>%d</>\n"
		"<Small>法力消耗: </><ManaCost>%.1f</>\n"
		"<Small>冷却时间: </><Cooldown>%.1f</>\n\n"
		"<Default>描述:</>\n"
		"%s\n"
		),
		*Title.ToString(),
		Level,
		ManaCost,
		Cooldown,
		*FormattedDescription);
}
//通用下一级描述生成模板函数
FString UBaseGameplayAbility::FormatNextLevelDescription(int32 Level, const FText& Title, const FText& Description, const TArray<FStringFormatArg>& Args) const
{
	FString FormattedDescription;
	if (!Description.IsEmpty())
	{
		FormattedDescription = FString::Format(*Description.ToString(), Args);
		FormattedDescription = FormattedDescription.Replace(TEXT("\\n"), TEXT("\n"));
	}
	
	const float ManaCost = FMath::Abs(GetManaCost(Level));
	const float Cooldown = GetCooldown(Level);
	
	return FString::Printf(TEXT(
		"<Title>下一级 %s</>\n"
		"<Small>等级: </><Level>%d</>\n"
		"<Small>法力消耗: </><ManaCost>%.1f</>\n"
		"<Small>冷却时间: </><Cooldown>%.1f</>\n\n"
		"<Default>描述:</>\n"
		"%s\n"
		),
		*Title.ToString(),
		Level,
		ManaCost,
		Cooldown,
		*FormattedDescription);
}
//获取法力消耗
float UBaseGameplayAbility::GetManaCost(float InLevel) const
{
	//这个是用于取出法力消耗 修改器信息 返回数值
	float ManaCost = 0.f;
	//GAS的获取 技能成本游戏效果函数
	if (const UGameplayEffect* CostEffect = GetCostGameplayEffect())
	{
		//遍历修改器信息 找到法力消耗修改器
		for (FGameplayModifierInfo Mod: CostEffect->Modifiers)
		{
			//判断修改器的属性 是否为法力属性
			if (Mod.Attribute == UBaseAttributeSet::GetManaAttribute())
			{
				Mod.ModifierMagnitude.GetStaticMagnitudeIfPossible(InLevel,ManaCost);
				break;
			}
		}
	}
	return ManaCost;
}
//获取冷却时间
float UBaseGameplayAbility::GetCooldown(float InLevel) const
{
	//这个是用于取出冷却时间 修改器信息 返回数值
	float Cooldown = 0.f;
	//GAS的获取 技能冷却时间游戏效果函数
	if (const UGameplayEffect* CooldownEffect = GetCooldownGameplayEffect())
	{
		//获取冷却时间
		CooldownEffect->DurationMagnitude.GetStaticMagnitudeIfPossible(InLevel,Cooldown);
	}
	return Cooldown;
}
